#include "hardview.h"

Hardview::Hardview()
{
    this->resize(1400,800);//大小要刚好和图片相等。
    this->setWindowTitle("Hard");//设置主窗口标题。
    this->setAutoFillBackground(true);//子窗体盖过父窗体；
    this->setWindowIcon(QIcon("C:/Users/jyh/Desktop/Fishing-files/fishing-files/img/Icon.png"));//设置窗口图标，图标的名字.png写在括号里。
    this->setBackgroundBrush(QBrush(QPixmap("C:/Users/jyh/Desktop/Fishing-files/fishing-files/img/fishingBackground.jpg")));

    this->setMouseTracking(true);

    scence=new QGraphicsScene;
    scence->setSceneRect(0,0,this->width()-2,this->height()-2);//视图左上角是原点；场景的原点在正中心；
    this->setScene(scence);

    //大炮：
    gun=new QGun("C:/Users/jyh/Desktop/Fishing-files/fishing-files/img/gun.png",scence);
    gun->setPos(this->width()/2,this->height()-20);
    //scence->addItem(gun);

    //鱼：
    fish1=new QFish("C:/Users/jyh/Desktop/Fishing-files/fishing-files/img/fish1.png",scence);
    //fish11=new QFish("C:/Users/jyh/Desktop/Fishing-files/fishing-files/img/fish1.png",scence);
    //fish12=new QFish("C:/Users/jyh/Desktop/Fishing-files/fishing-files/img/fish1.png",scence);
    //fish13=new QFish("C:/Users/jyh/Desktop/Fishing-files/fishing-files/img/fish1.png",scence);
    //fish14=new QFish("C:/Users/jyh/Desktop/Fishing-files/fishing-files/img/fish1.png",scence);
    //fish15=new QFish("C:/Users/jyh/Desktop/Fishing-files/fishing-files/img/fish1.png",scence);
    //fish1->setPos(-1400,100);
    //scence->addItem(fish1);

    fish2=new QFish("C:/Users/jyh/Desktop/Fishing-files/fishing-files/img/fish2.png",scence);
    //fish21=new QFish("C:/Users/jyh/Desktop/Fishing-files/fishing-files/img/fish2.png",scence);
    //fish22=new QFish("C:/Users/jyh/Desktop/Fishing-files/fishing-files/img/fish2.png",scence);
    //fish2->setPos(-1000,200);
    //scence->addItem(fish2);

    fish3=new QFish("C:/Users/jyh/Desktop/Fishing-files/fishing-files/img/fish3.png",scence);
    //fish31=new QFish("C:/Users/jyh/Desktop/Fishing-files/fishing-files/img/fish3.png",scence);
    //fish3->setPos(-600,300);
    //scence->addItem(fish3);

    //fish4=new QFish("C:/Users/jyh/Desktop/Fishing-files/fishing-files/img/fish4.png",scence);
    //fish4->setPos(-200,400);
    //scence->addItem(fish4);

    fish5=new QFish("C:/Users/jyh/Desktop/Fishing-files/fishing-files/img/fish5.png",scence);
    //fish5->setPos(-600,500);
    //scence->addItem(fish5);

    //fish6=new QFish("C:/Users/jyh/Desktop/Fishing-files/fishing-files/img/fish6.png",scence);
    //fish61=new QFish("C:/Users/jyh/Desktop/Fishing-files/fishing-files/img/fish6.png",scence);
    //fish62=new QFish("C:/Users/jyh/Desktop/Fishing-files/fishing-files/img/fish6.png",scence);
    //fish63=new QFish("C:/Users/jyh/Desktop/Fishing-files/fishing-files/img/fish6.png",scence);
    //fish64=new QFish("C:/Users/jyh/Desktop/Fishing-files/fishing-files/img/fish6.png",scence);
    //fish65=new QFish("C:/Users/jyh/Desktop/Fishing-files/fishing-files/img/fish6.png",scence);
    //fish66=new QFish("C:/Users/jyh/Desktop/Fishing-files/fishing-files/img/fish6.png",scence);
    //fish6->setPos(-800,600);
    //scence->addItem(fish6);

    //定时器：
    timer=new QTimer;
    connect(timer,SIGNAL(timeout()),scence,SLOT(advance()));
    timer->start(60);//一毫秒刷新一次；

    //分数的显示：
    label=new QLabel(this);
    //label->setGeometry(200,100,6500,1200);
    QPalette color;
    color.setColor(QPalette::WindowText,Qt::blue);
    QFont font;
    font.setPointSize(26);
    label->setContentsMargins(30,0,0,0);
    label->setPalette(color);
    label->setFont(font);
    label->setText("Energe: "+QString::number(score));
    //scence->addWidget(label);


}
void Hardview::resizeEvent(QResizeEvent *event)
{
    this->setBackgroundBrush(QBrush(QPixmap("C:/Users/jyh/Desktop/Fishing-files/fishing-files/img/fishingBackground.jpg").scaled(event->size(),Qt::IgnoreAspectRatio,Qt::SmoothTransformation)));
}//全屏实现；
void Hardview::mouseMoveEvent(QMouseEvent *event){
    QPoint p;
    p=event->pos();

    //连线：
    QLine line(this->width()/2,this->height(),p.x(),p.y());

    QLineF linef(line);
    gun->setRotation(90-linef.angle()+9);
}//潜艇和炮跟着鼠标转动；
void Hardview::mousePressEvent(QMouseEvent *event){
    if(score<=0) {
        this->label->setText("You Lost!!!");
        if(QMessageBox::No==QMessageBox::question(this,"Oh, no!","You have ran out of the energe!!! Wanna try again?")) {
            this->close();
        } else {
            score=50;
            this->label->setText("Energe: "+QString::number(score));
        }
    } else if(score>=100) {
        this->label->setText("You Win!!!");
        if(QMessageBox::Yes==QMessageBox::question(this,"Congratulations!","The energe has been filled up, set out for a new trip!")) {
            this->close();
        } else {
            score=50;
            this->label->setText("Energe: "+QString::number(score));
        }
    } else {
        score=score-8;
        this->label->setText("Energe: "+QString::number(score));
    }
    QPoint p=event->pos();
    QLineF linef(this->width()/2,this->height(),p.x(),p.y());
    QBang *bang=new QBang("C:/Users/jyh/Desktop/Fishing-files/fishing-files/img/bang.png",scence,linef.angle());
}//点击出现炮弹；

